<template>
  <!-- 求职意向 -->
  <Top-Page class="intention-list-wrap">
    <cu-custom bgColor="bg-gradual-white-3" :isBack="true">
      <template #backText></template>
      <template #content>管理求职意向</template>
      <template #right>
        <image class="more" src="../../../static/image/common/w-more.png" mode="widthFix" />
      </template>
    </cu-custom>

    <view class="content">
      <view class="title">管理求职意向</view>

      <view class="sub-title">我们会根据您的“求职意向”在首页展示合适的职位</view>

      <view class="job-status">
        <view class="">求职状态</view>
        <view class="status" @click="jobWantedShow = !jobWantedShow">{{ jobWantedList[jobWantedStatu] }}</view>
      </view>

      <view class="intention-list">
        <template v-for="item in list">
          <view class="intention-list-item" v-if="!!item.id" :key="item" @click="toAmend(item)">
            <view class="list-top">
              <view class="list-title">
                {{ item.industry_parent }}
              </view>
              <view class="iconfont icon-m01"></view>
            </view>

            <view class="li">
              <view class="li-item">{{ item.salary_min }}K - {{ item.salary_max }}K</view>
              <view class="li-item">{{ item.province }}{{ item.city }}</view>
              <view class="li-item">{{ item.nature }}</view>
            </view>
            <view class="li">
              {{ item.industry }}
            </view>
          </view>
        </template>
      </view>
    </view>

    <view class="add" @click="add">添加求职意向</view>

    <Popups v-model:show="jobWantedShow" position="bottom" class="job-wanted-list-wrap">
      <view class="job-wanted-list">
        <view
          v-for="(item, index) in jobWantedList"
          :class="['job-wanted-list__item', { 'job-wanted-list__item-on': index === jobWantedStatu }]"
          :key="item"
          @click="statusChange(index)"
        >
          {{ item }}
        </view>
      </view>
    </Popups>
  </Top-Page>
</template>

<script lang="ts" setup>
import Popups from "@/components/Popups/index";
import { ref, reactive } from "vue";
import recruitApi from "@/api/recruit.js"; //招聘相关API
import { onShow } from "@dcloudio/uni-app";

const jobWantedShow = ref(false);
const jobWantedStatu = ref(0);
const jobWantedList = uni.getStorageSync("config").status;
const list: any[] = reactive([]);

onShow(() => {
  init();
});

const toAmend = (item: any) => {
  uni.setStorageSync("amend-intention", item);

  uni.navigateTo({
    url: `/pages/recruit/intention/add-amend?id=${item.id}`
  });
};

const statusChange = (index: number) => {
  uni.showToast({
    title: "更新中...",
    duration: 999999,
    mask: true,
    icon: "loading"
  });

  recruitApi
    .statuschange({
      status: index
    })
    .then((res) => {
      uni.hideToast();
      jobWantedShow.value = false;
      jobWantedStatu.value = index;
    });
};

const add = () => {
  uni.navigateTo({
    url: "/pages/recruit/intention/add-amend"
  });
};

function init() {
  recruitApi.mine().then((res) => {
    uni.setStorageSync("mine", res.data);

    list.length = 0;
    list.push(...res.data.intention);
  });
}
</script>

<style lang="scss" scoped>
@import "./index.scss";
</style>
